package ustc.xiaoyang.karl.binarysearch;

public class TheSquareRootOfX69 {
    public static void main(String[] args) {

        System.out.println(new TheSquareRootOfX69().mySqrt(8));
    }
    public int mySqrt(int x){
        int left = 0, right = x;
        while(left <= right){
            int mid = left + (right - left) / 2;
            if((long)mid * mid < x){
                left = mid + 1;
            }else if((long)mid * mid > x){
                right = mid - 1;
            }else{
                return mid;
            }
        }
        return right;
    }
}
